{% extends 'base.html' %}

{% block title %}我发起的活动 - 本地有约{% endblock %}

{% block content %}
<div class="container py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>我发起的活动</h2>
        <a href="{% url 'event_create' %}" class="btn btn-primary">
            <i class="fas fa-plus me-2"></i>创建新活动
        </a>
    </div>

    {% if events %}
    <div class="row">
        {% for event in events %}
        <div class="col-md-6 col-lg-4 mb-4">
            <div class="card h-100">
                {% if event.images.exists %}
                <img src="{{ event.images.first.image.url }}" class="card-img-top" alt="{{ event.title }}" style="height: 200px; object-fit: cover;">
                {% else %}
                <div class="bg-light d-flex align-items-center justify-content-center" style="height: 200px;">
                    <i class="fas fa-calendar fa-3x text-muted"></i>
                </div>
                {% endif %}
                <div class="card-body">
                    <h5 class="card-title">{{ event.title }}</h5>
                    <p class="card-text text-muted small">{{ event.description|truncatewords:20 }}</p>
                    <div class="mb-2">
                        <span class="badge {% if event.status == 'published' %}bg-success{% elif event.status == 'draft' %}bg-secondary{% elif event.status == 'cancelled' %}bg-danger{% else %}bg-warning{% endif %}">
                            {{ event.get_status_display }}
                        </span>
                    </div>
                    <div class="d-flex justify-content-between text-muted small mb-2">
                        <span><i class="fas fa-users me-1"></i>{{ event.current_participants }}/{{ event.max_participants }}</span>
                        <span><i class="fas fa-eye me-1"></i>{{ event.views_count }}</span>
                    </div>
                    <div class="d-flex gap-2">
                        <a href="{% url 'event_detail' event.id %}" class="btn btn-outline-primary btn-sm">查看</a>
                        <a href="{% url 'event_edit' event.id %}" class="btn btn-outline-secondary btn-sm">编辑</a>
                    </div>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
    {% else %}
    <div class="text-center py-5">
        <i class="fas fa-calendar-plus fa-4x text-muted mb-3"></i>
        <h4 class="text-muted">还没有发起任何活动</h4>
        <p class="text-muted mb-4">创建你的第一个活动，邀请大家一起来参与吧！</p>
        <a href="{% url 'event_create' %}" class="btn btn-primary btn-lg">创建活动</a>
    </div>
    {% endif %}
</div>
{% endblock %}